/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.employee.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.employee.entity.StatutoryHolidays;
import com.thinkgem.jeesite.modules.employee.service.StatutoryHolidaysService;

/**
 * 公共假期Controller
 * @author hui.li
 * @version 2017-07-18
 */
@Controller
@RequestMapping(value = "${adminPath}/employee/statutoryHolidays")
public class StatutoryHolidaysController extends BaseController {

	@Autowired
	private StatutoryHolidaysService statutoryHolidaysService;
	
	@ModelAttribute
	public StatutoryHolidays get(@RequestParam(required=false) String id) {
		StatutoryHolidays entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = statutoryHolidaysService.get(id);
		}
		if (entity == null){
			entity = new StatutoryHolidays();
		}
		return entity;
	}
	
	@RequiresPermissions("employee:statutoryHolidays:view")
	@RequestMapping(value = {"list", ""})
	public String list(StatutoryHolidays statutoryHolidays, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<StatutoryHolidays> page = statutoryHolidaysService.findPage(new Page<StatutoryHolidays>(request, response), statutoryHolidays); 
		model.addAttribute("page", page);
		return "modules/employee/statutoryHolidaysList";
	}

	@RequiresPermissions("employee:statutoryHolidays:view")
	@RequestMapping(value = "form")
	public String form(StatutoryHolidays statutoryHolidays, Model model) {
		model.addAttribute("statutoryHolidays", statutoryHolidays);
		return "modules/employee/statutoryHolidaysForm";
	}

	@RequiresPermissions("employee:statutoryHolidays:edit")
	@RequestMapping(value = "save")
	public String save(StatutoryHolidays statutoryHolidays, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, statutoryHolidays)){
			return form(statutoryHolidays, model);
		}
		statutoryHolidaysService.save(statutoryHolidays);
		addMessage(redirectAttributes, "保存公共假期成功");
		return "redirect:"+Global.getAdminPath()+"/employee/statutoryHolidays/?repage";
	}
	
	@RequiresPermissions("employee:statutoryHolidays:edit")
	@RequestMapping(value = "delete")
	public String delete(StatutoryHolidays statutoryHolidays, RedirectAttributes redirectAttributes) {
		statutoryHolidaysService.delete(statutoryHolidays);
		addMessage(redirectAttributes, "删除公共假期成功");
		return "redirect:"+Global.getAdminPath()+"/employee/statutoryHolidays/?repage";
	}

}